<style scoped>
.expire-outer{display: flex;width: 100%;height: 100%;justify-content: center;align-items: center;}
.expire-outer .canvas img{width: 100%;}
</style>
<template>
  <div class="expire-outer">
    <div style="padding: 20px 50px;font-size: 24px;text-align: center;">
      <div class="canvas" style="width: 250px;margin: auto;">
        <img v-if="ewm" :src="ewm" alt="">
      </div>
      <p style="padding: 20px 0;">微信扫码打开续期页面</p>
      <div>
        <p v-if="tenant.expiration_status!=1" style="color: red;margin-right: 10px;">已过期，到期时间：{{tenant.expiration_time}}</p>
        <p v-else style="margin-right: 10px;">到期时间：{{tenant.expiration_time}}</p>

        <p v-if="tenant.expiration_status!=1" style="color: red;margin-right: 10px;">最大逾期截止时间：{{tenant.max_expiration_time.substring(0, 10)}}，超过截至时间后将禁止登录系统。</p>

        <el-button type="primary" @click="refresh">刷新</el-button>
        <el-button v-if="tenant.expiration_status!=0 && !__iframe" @click="href_handle('/index')">前往首页</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import qrcode from "qrcode"
import {_config} from "@/js/s94_tool.js";
import {href_handle} from "@/js/tool.js";
import {ajax} from "@/js/api_tool.js";

export default {
  props: ['__iframe'],
  data(){
    let tenant = _config('this_tenant', {});
    tenant.max_expiration_time = tenant.max_expiration_time || '';
    return {
      ewm:'',
      tenant: tenant,
    }
  },
  methods: {
    href_handle: href_handle,
    refresh(){
      let app = this;
      ajax('/admin/index/config', (res)=>{
        let tenant = res.data.tenant;
        _config({this_tenant: tenant});
        this.tenant = tenant;
        return false;
      })
    }
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

    let host = _config('config.system.host');
    let encode_id = this.tenant.encode_id;
    let href = '//'+host+'/html/home/tenant/add_time.html?encode_id='+encodeURIComponent(encode_id);
    href = (new URL(href, window.location.href)).href;
    qrcode.toDataURL(href).then(function (v){
      app.ewm = v;
    });
  }
};
</script>